package com.yanqu.road.dao.impl.activity.pixiu;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.pixiu.config.PiXiuAmuseInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class PiXiuConfigDaoImpl extends TempDao {

    private static String getPiXiuAmuseInfoSql = "select * from `t_s_activity_pixiu_amuse` where `activityId`=? ORDER BY `id` ASC";
    public List<PiXiuAmuseInfo> getPiXiuAmuseInfoList(int activityId) {
        List<PiXiuAmuseInfo> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getPiXiuAmuseInfoSql);
            int i = 1;
            call.setInt(i, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                PiXiuAmuseInfo piXiuAmuseInfo = new PiXiuAmuseInfo();
                piXiuAmuseInfo.setActivityId(rs.getInt("activityId"));
                piXiuAmuseInfo.setId(rs.getInt("id"));
                piXiuAmuseInfo.setType(rs.getInt("type"));
                piXiuAmuseInfo.setItemId(rs.getInt("itemId"));
                piXiuAmuseInfo.setItemNumList(StringUtils.stringToIntegerList(rs.getString("itemNum"), "\\|"));
                list.add(piXiuAmuseInfo);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
